function posterior = updatePosteriorUncertainty(mix, data, vars, reg)


% update each component
for k = 1:mix.ncentres
    w = vars.Z(:, k);
    mydata.Y = vars.R(:, :, k);
    mydata.C = vars.E(:, :, :, k);
    mydata.YYt = vars.RRt(:, :, :, k);

    varposterior = computeBayesGaussianUncertainty(mix.varprior, mydata, w, mix.covar_type, reg);
  
    if isfield(mix.varprior, 'a0')
        posterior.a(k) = mix.varprior.a0 + sum(w);
    end
    posterior.m(k, :) = varposterior.m;
    posterior.b(k) = varposterior.b;
    posterior.W(:, :, k) = varposterior.W;
    posterior.v(k) = varposterior.v;
    posterior.ElndetLambda(k) = wishart_exp_logdet(posterior.W(:, :, k), posterior.v(k));
end
